package com.Gameplay.Combat.CombatManagement;
//战斗系统管理，统一管理所有模块

import com.Gameplay.Combat.Attack.AttackType;
import com.Gameplay.Combat.Attack.Impl.FistAttack;
import com.Gameplay.Combat.Attack.Impl.LegsAttack;
import com.Gameplay.Combat.Attack.ParentAttack;
import com.Gameplay.Combat.Defend.Impl.NormalDefend;
import com.Gameplay.Combat.Defend.ParentDefend;


import com.Gameplay.Combat.Hurtbox.FistHurtbox;
import com.Gameplay.Combat.Hurtbox.LegsHurtbox;
import com.Gameplay.character.Role.parentRole;
import javafx.scene.input.KeyCode;

import java.util.ArrayList;
import java.util.Arrays;

//战斗系统管理，统一管理所有模块
public class CombatManagement {

    private final ParentAttack FistAttack = new FistAttack();
    private final ParentAttack LegsAttack = new LegsAttack();
    private final ParentDefend NormalDefend = new NormalDefend();
    private final FistHurtbox fistBox = new FistHurtbox();
    private final LegsHurtbox legsBox = new LegsHurtbox();
    private final ArrayList<Double> information = new ArrayList<>();

    public ArrayList<Double> FistCombat(KeyCode keys, parentRole p1, parentRole P2) {
        information.clear();
        double damage = 0;
        double energy = 0;
        setAttackForm(keys, p1);
        //Update attack Type
        if (isFistAttacked(fistBox, P2)) {
            if (P2.isIsblocking()) {
                energy = NormalDefend.defend(P2.isIsblocking(), FistAttack.getDamage());
            } else {
                damage = FistAttack.getDamage();
            }
        }
        information.add(0, damage);
        information.add(1, energy);
        return information;


    }

    public ArrayList<Double> LegsCombat(KeyCode keys, parentRole p1, parentRole P2) {
        information.clear();
        double damage = 0;
        double energy = 0;
        setAttackForm(keys, p1);

        if (isLegsAttacked(legsBox, P2)) {
            if (P2.isIsblocking()) {
                energy = NormalDefend.defend(P2.isIsblocking(), LegsAttack.getDamage());
            } else {
                damage = LegsAttack.getDamage();
            }
        }
        information.add(0, damage);
        information.add(1, energy);
        return information;
    }


    public boolean isFistAttacked(FistHurtbox fistHurtbox, parentRole p2) {

        return fistHurtbox.getRwidth() >= p2.getRoleBox().getLwidth() &&
                fistHurtbox.getUheight() <= p2.getRoleBox().getUheight() &&
                fistHurtbox.getDheight() >= p2.getRoleBox().getDheight();
    }

    public boolean isLegsAttacked(LegsHurtbox legsHurtbox, parentRole p2) {
        return legsHurtbox.getRwidth() >= p2.getRoleBox().getLwidth() &&
                legsHurtbox.getUheight() <= p2.getRoleBox().getUheight() &&
                legsHurtbox.getDheight() >= p2.getRoleBox().getDheight();
    }

    public void setAttackForm(KeyCode keys, parentRole p1) {
        switch (keys) {
            case U: {
                fistBox.setFistBox(p1.getCurrentX(), p1.getCurrentY(), p1.getFacing(), AttackType.Light);
                FistAttack.setAttackDamage(AttackType.Light);
                break;
            }
            case I: {
                fistBox.setFistBox(p1.getCurrentX(), p1.getCurrentY(), p1.getFacing(), AttackType.Middle);
                FistAttack.setAttackDamage(AttackType.Middle);
                break;
            }
            case O: {
                fistBox.setFistBox(p1.getCurrentX(), p1.getCurrentY(), p1.getFacing(), AttackType.Heavy);
                FistAttack.setAttackDamage(AttackType.Heavy);
                break;
            }
            case J: {
                legsBox.setLegsBox(p1.getCurrentX(), p1.getCurrentY(), p1.getFacing(), AttackType.Light);
                LegsAttack.setAttackDamage(AttackType.Light);
                break;
            }
            case K: {
                legsBox.setLegsBox(p1.getCurrentX(), p1.getCurrentY(), p1.getFacing(), AttackType.Middle);
                LegsAttack.setAttackDamage(AttackType.Middle);
                break;
            }
            case L: {
                legsBox.setLegsBox(p1.getCurrentX(), p1.getCurrentY(), p1.getFacing(), AttackType.Heavy);
                LegsAttack.setAttackDamage(AttackType.Heavy);
                break;
            }

        }
    }

    public void addInformation(double damage, double enen) {


    }
}







